#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define maxn 101
const int INF = 1<<29;

int n,s,t;
vector<pair<int, int> > G[maxn];
int dis[maxn];
bool visited[maxn];

void SPFA(int s) {
	for (int i = 0; i <= n; i++) dis[i] = INF;
	queue<int> que;
	dis[s] = 0;
	visited[s] = true;
	que.push(s);
	int u;
	while (!que.empty()) {
		u = que.front(); que.pop();
		visited[u] = false;
		for (auto son : G[u]) {
			int v = son.first;
			int w = son.second;
			if (dis[v] > dis[u] + w) {
				dis[v] = dis[u] + w;
				if (!visited[v]) {
					que.push(v);
					visited[v] = true;
				}
			}
		}
	}
}

int main(){
	cin>>n>>s>>t;
	for(int i=1; i<=n; i++){
		int k,v;
		cin>>k;
		for(int j=0; j<k; j++){
			cin>>v;
			if(j==0) G[i].push_back(make_pair(v, 0));
			else G[i].push_back(make_pair(v, 1));
		}
	}
	SPFA(s);
	if(dis[t] < INF-1) cout << dis[t] << endl;
	else cout << "-1" << endl;
	return 0;
}